<template>
    <div class="login_container">
        <div class="box_bg"></div>
        <div class="login_box">
            <!-- 头像区域-->
            <div class="avatar_box">
                <img src="@/assets/images/logo.svg"></img>
            </div>
            <!-- 登陆表单区域-->
            <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form">
                <!-- 用户名-->
                <el-form-item prop="loginName">
                    <el-input v-model="loginForm.loginName" prefix-icon="el-icon-user-solid"></el-input>
                </el-form-item>
                <!-- 密码-->
                <el-form-item prop="pwd">
                    <el-input v-model="loginForm.pwd" prefix-icon="el-icon-lock" type="password"></el-input>
                </el-form-item>
                <!-- 语言-->
                <el-form-item>
                    <template>
                        <el-radio v-model="lang" label="zh_CN">简体中文</el-radio>
                        <el-radio v-model="lang" label="en_US">英文</el-radio>
                    </template>
                </el-form-item>
                <!-- 按钮-->
                <el-form-item>
                    <el-button type=""success" @clicl="submitForm">登陆</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import Request from '@/js/Request.js'

export default {
    name: 'login',
    data () {
        return {
            loginForm: {
                loginNme: '',
                pwd: ''
            },
            loginFormRules: {},
            alertMsgShow: 'none',
            lang: 'zh_CN',
            alertMsgText: '未知错误'
        }
    },
    components: {
    },
    mounted: ()) => {
    },
    methods: {
        submitForm () {
            Request.requestHandler(Request.request.post('/doLoginRest?lang=' + this.lang, this.loginForm), true).then((data) => {
                //根据数据结构进行更改
                if (data.data.code === 0) {
                    data.data.data.loginUserMenu.forEach((menu, index) => {
                        if (index === 2) {
                            sessionStorage.setItem('unclolapseNo', 'm-' + menu.id)
                        }
                    })
                    localStorage.setItem('currentLocale', this.lang)
                    localStorage.setItem('loginUserMenu', JSON.stringify(data.data.data.loginUserMenu))
                    localStorage.setItem('loginUser', JSON.stringify(data.data.data.loginUser))
                    this.$router.push('/home')
                } else {
                    this.$message.error(data.data.msg)
                }
            }).catch(data => {
                this.$message.error('未知错误')
            })
        }
    }
}
</script>

<style lang="less" scoped>
.login_container {
    background-color: #2b4b6b;
    height: 100%;
}
.box_bg {
    position: absolute;
    background-color: rgba(26, 188, 156, 1);
    height: 220px;
    width: 100%;
    top: 30%;
}

@formWidth: 450px;

.log_box {
    width: @formWidth;
    height: 300px;
    background-color: #fff;
    border-radius: 3px;
    position: absolute;
    left: 70%;
    top: 50%;
    transform: translate(-50%, -50%);

    .avatar_box {
        height: 80px;
        width: 80px;
        border: 1px solid #eee;
        border-radius: 50%;
        padding: 10px;
        box-shadow: 0 0 10px #ddd;
        position: absolute;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: #fff;
        img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background-color: #eee;
        }
    }
}

.login_form {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
}

.btns {
    display: flex;
    justify-content: flex-end;
}

.btns button {
    width: @formWidth - 40px;
}
</style>
